package cfar.ff.fun;

/**
 *
 * @author badi
 */
public final class Curry {

    public static <A, B> F0<B> curry(final F1<A, B> f, final A a) {
        return new F0<B>() {

            public B call() {
                return f.f(a);
            }
        };
    }

    public static <A, B, C> F1<B, C> curry(final F2<A, B, C> f, final A a) {
        return new F1<B, C>() {

            public C f(B b) {
                return f.f(a, b);
            }
        };
    }

    public static <A,B,C,D> F2<B,C,D> curry(final F3<A,B,C,D> f, final A a){
        return new F2<B,C,D>() {

            public D f(B b, C c) {
                return f.f(a, b, c);
            }
        };
    }

    public static <A,B,C,D,E> F3<B,C,D,E> curry(final F4<A,B,C,D,E> f, final A a){
        return new F3<B, C, D, E>() {

            public E f(B b, C c, D d) {
                return f.f(a, b, c, d);
            }
        };
    }

    public static <A,B,C,D,E,F> F4<B,C,D,E,F> curry(final F5<A,B,C,D,E,F> f, final A a){
        return new F4<B, C, D, E, F>() {

            public F f(B b, C c, D d, E e) {
                return f.f(a, b, c, d, e);
            }
        };
    }
}
